package com.ai.service.made.impl;

import com.ai.common.CommonResponse;
import com.ai.entity.cameraFunctions.functions.CameraFunctionsPO;
import com.ai.entity.cameraFunctions.regions.RegionsConfigPO;
import com.ai.entity.function.FunctionPO;
import com.ai.entity.made.BaseIdOrNameBO;
import com.ai.mapper.made.RegionsConfigMapper;
import com.ai.service.made.CameraFunctionsService;
import com.ai.service.made.FunctionService;
import com.ai.service.made.RegionsConfigService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author Mr.Chen
 * @since 2020-08-20
 */
@Service
public class RegionsConfigServiceImpl extends ServiceImpl<RegionsConfigMapper, RegionsConfigPO> implements RegionsConfigService {

    @Autowired
    FunctionService functionService;
    @Autowired
    CameraFunctionsService cameraFunctionsService;

    @Override
    public CommonResponse selectByFunction(BaseIdOrNameBO baseIdOrNameBO) {
        FunctionPO functionPO = null;
        CameraFunctionsPO cameraFunctionsPO = null;
        if (baseIdOrNameBO.getId() != null && baseIdOrNameBO.getId() != 0) {
            cameraFunctionsPO = cameraFunctionsService.getById(baseIdOrNameBO.getId());
            if (cameraFunctionsPO != null) {
                functionPO = functionService.getById(cameraFunctionsPO.getFunctionId());
            }
        }
        List<RegionsConfigPO> regionsConfigPOList;
        if (cameraFunctionsPO == null || functionPO == null) {
            regionsConfigPOList = list(new QueryWrapper<RegionsConfigPO>().eq("type", "0"));
        } else {
            regionsConfigPOList = list(new QueryWrapper<RegionsConfigPO>().eq("type", "0").or().eq("type", functionPO.getType()));
        }
        return CommonResponse.ok(regionsConfigPOList);
    }
}
